﻿using System;
using System.Collections.Generic;
using KKSG;
using MiniJSON;
using UILib;
using UnityEngine;
using XMainClient.UI.UICommon;
using XUpdater;
using XUtliPoolLib;

namespace XMainClient.UI
{
	// Token: 0x0200178A RID: 6026
	internal class GameCommunityHandler : DlgHandlerBase
	{
		// Token: 0x1700383D RID: 14397
		// (get) Token: 0x0600F89B RID: 63643 RVA: 0x0038D5C8 File Offset: 0x0038B7C8
		protected override string FileName
		{
			get
			{
				return "GameSystem/GameCommunityDlg";
			}
		}

		// Token: 0x0600F89C RID: 63644 RVA: 0x0038D5E0 File Offset: 0x0038B7E0
		protected override void Init()
		{
			base.Init();
			this._doc = XDocuments.GetSpecificDocument<XMainInterfaceDocument>(XMainInterfaceDocument.uuID);
			this.m_Bg = (base.transform.Find("Bg/Bg").GetComponent("XUISprite") as IXUISprite);
			this.m_SystemParent = base.transform.Find("Bg/Sys");
			//zcg XSingleton<XChatIFlyMgr>.singleton.RefreshWebViewConfig();
		}

		// Token: 0x0600F89D RID: 63645 RVA: 0x0038D64C File Offset: 0x0038B84C
		protected override void OnShow()
		{
			base.OnShow();
			bool flag = XSingleton<XLoginDocument>.singleton.Channel == XAuthorizationChannel.XAuthorization_QQ;
			int num = 0;
			int num2 = 0;
			for (int i = 0; i < this._doc.GameCommunityReader.Table.Length; i++)
			{
				GameCommunityTable.RowData rowData = this._doc.GameCommunityReader.Table[i];
				IXUIButton ixuibutton = this.m_SystemParent.Find(rowData.ButtonName).GetComponent("XUIButton") as IXUIButton;
				ixuibutton.SetVisible(false);
				GameObject gameObject = ixuibutton.gameObject.transform.Find("RedPoint").gameObject;
				if (i == 0)
				{
					num2 = ixuibutton.spriteWidth;
					if (!this._widthInit)
					{
						this._widthInit = true;
						this._bgWidthDelta = this.m_Bg.spriteWidth - num2;
					}
				}
				if ((ulong)XSingleton<XAttributeMgr>.singleton.XPlayerData.Level >= (ulong)((long)rowData.OpenLevel))
				{
					if (XSingleton<XGameSysMgr>.singleton.IsSystemOpened((XSysDefine)rowData.SysID))
					{
						if (this.LoginStateTrue(rowData))
						{
							if (rowData.ID == 13)
							{
								if (this.IsSuportReplay())
								{
									ixuibutton.SetVisible(true);
									ixuibutton.gameObject.transform.localPosition = new Vector3((float)(num * num2), 0f);
									ixuibutton.ID = (ulong)((long)rowData.ID);
									ixuibutton.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnSysBtnClick));
									num++;
								}
							}
							else
							{
								if (rowData.ID == 12)
								{
									if (this.GetQuestionnaireStage() != 0)
									{
										ixuibutton.SetVisible(true);
										ixuibutton.gameObject.transform.localPosition = new Vector3((float)(num * num2), 0f);
										ixuibutton.ID = (ulong)((long)rowData.ID);
										ixuibutton.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnSysBtnClick));
										num++;
										gameObject.SetActive(XSingleton<XGameSysMgr>.singleton.GetSysRedPointStateConsiderBlock(XSysDefine.XSys_Questionnaire));
									}
								}
								else
								{
									if (rowData.ID == 14)
									{
										XSingleton<XDebug>.singleton.AddLog("Is show tv: ", this._doc.ShowWebView.ToString(), null, null, null, null, XDebugColor.XDebug_None);
										bool flag12 = SystemInfo.processorType.StartsWith("Intel");
										int num3 = int.Parse(XSingleton<XGlobalConfig>.singleton.GetValue("HideWebView"));
										bool flag13 = SystemInfo.systemMemorySize >= XSingleton<XGlobalConfig>.singleton.GetInt("WebMemory");
										XSingleton<XDebug>.singleton.AddLog("memory: ", flag13.ToString(), " x86: ", flag12.ToString(), " hide: ", num3.ToString(), XDebugColor.XDebug_None);
										bool flag14 = this._doc.ShowWebView && num3 != 1 && !flag12 && flag13;
										ixuibutton.SetVisible(flag14);
										if (flag14)
										{
											ixuibutton.gameObject.transform.localPosition = new Vector3((float)(num * num2), 0f);
											ixuibutton.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnSysBtnClick));
											num++;
											ixuibutton.ID = (ulong)((long)rowData.ID);
										}
									}
									else
									{
										bool flag16 = rowData.ID == 8 && (XSingleton<XLoginDocument>.singleton.GetLaunchTypeServerInfo() != StartUpType.StartUp_QQ || XSingleton<XLoginDocument>.singleton.Channel != XAuthorizationChannel.XAuthorization_QQ);
										if (!flag16)
										{
											bool flag17 = rowData.ID == 9 && (XSingleton<XLoginDocument>.singleton.GetLaunchTypeServerInfo() != StartUpType.StartUp_WX || XSingleton<XLoginDocument>.singleton.Channel != XAuthorizationChannel.XAuthorization_WeChat);
											if (!flag17)
											{
												ixuibutton.SetVisible(true);
												ixuibutton.gameObject.transform.localPosition = new Vector3((float)(num * num2), 0f);
												ixuibutton.ID = (ulong)((long)rowData.ID);
												ixuibutton.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnSysBtnClick));
												num++;
												gameObject.SetActive(XSingleton<XGameSysMgr>.singleton.GetSysRedPointStateConsiderBlock((XSysDefine)rowData.SysID));
											}
										}
									}
								}
							}
						}
					}
				}
			}
			this.m_Bg.spriteWidth = this._bgWidthDelta + num * num2;
		}

		// Token: 0x0600F89E RID: 63646 RVA: 0x0038DACC File Offset: 0x0038BCCC
		private bool OnSysBtnClick(IXUIButton btn)
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			ulong id = btn.ID;
			ulong num = id - 1UL;
			if (num <= 15UL)
			{
				switch ((uint)num)
				{
				case 0U:
				{
					PtcC2G_CloseHintNtf ptcC2G_CloseHintNtf = new PtcC2G_CloseHintNtf();
					ptcC2G_CloseHintNtf.Data.systemid = (uint)XFastEnumIntEqualityComparer<XSysDefine>.ToInt(XSysDefine.XSys_GC_XinYueVIP);
					XSingleton<XClientNetwork>.singleton.Send(ptcC2G_CloseHintNtf);
					XSingleton<XGameSysMgr>.singleton.SetSysRedPointState(XSysDefine.XSys_GC_XinYueVIP, false);
					XSingleton<XGameSysMgr>.singleton.RecalculateRedPointState(XSysDefine.XSys_GameCommunity, true);
					GameObject gameObject = btn.gameObject.transform.Find("RedPoint").gameObject;
					gameObject.SetActive(false);
					string text = string.Format("{0}?game_id={1}&opencode={2}&partition_id={3}&role_id={4}", new object[]
					{
						XSingleton<XGlobalConfig>.singleton.GetValue("XinYueInternalURL"),
						XSingleton<XClientNetwork>.singleton.GameId,
						XSingleton<XClientNetwork>.singleton.OpenCode,
						XSingleton<XClientNetwork>.singleton.ServerID,
						XSingleton<XAttributeMgr>.singleton.XPlayerData.RoleID
					});
					XSingleton<XDebug>.singleton.AddLog("url = " + text, null, null, null, null, null, XDebugColor.XDebug_None);
					dictionary["url"] = text;
					dictionary["screendir"] = "SENSOR";
					XSingleton<XUpdater.XUpdater>.singleton.XPlatform.SendExtDara("open_url", Json.Serialize(dictionary));
					break;
				}
				case 6U:
					XSingleton<UiUtility>.singleton.OpenHtmlUrl("DeepLinkAddress");
					break;
				case 7U:
				case 8U:
					DlgBase<XQQWXGameCenterPrivilegeView, XQQWXGameCenterPrivilegeBehaviour>.singleton.SetVisibleWithAnimation(true, null);
					break;
				case 9U:
				{
					string text = string.Format("{0}?partition={1}&roleid={2}&area={3}&algorithm={4}&version={5}&timestamp={6}&appid={7}&openid={8}&sig={9}&encode={10}", new object[]
					{
						XSingleton<XGlobalConfig>.singleton.GetValue("MicroCommunityURL"),
						XSingleton<XClientNetwork>.singleton.ServerID,
						XSingleton<XAttributeMgr>.singleton.XPlayerData.RoleID,
						XSingleton<XClientNetwork>.singleton.AreaId,
						"v2",
						XSingleton<XUpdater.XUpdater>.singleton.Version,
						XSingleton<UiUtility>.singleton.GetTimeStamp(),
						XSingleton<XClientNetwork>.singleton.AppId,
						XSingleton<XLoginDocument>.singleton.OpenID,
						XSingleton<XUpdater.XUpdater>.singleton.XPlatform.GetMD5(string.Format("{0}{1}", XSingleton<XClientNetwork>.singleton.MSDKKey, XSingleton<UiUtility>.singleton.GetTimeStamp())),
						"2"
					});
					XSingleton<XDebug>.singleton.AddLog("url = " + text, null, null, null, null, null, XDebugColor.XDebug_None);
					dictionary["url"] = text;
					dictionary["screendir"] = "SENSOR";
					XSingleton<XUpdater.XUpdater>.singleton.XPlatform.SendExtDara("open_url", Json.Serialize(dictionary));
					break;
				}
				case 10U:
					XSingleton<UiUtility>.singleton.OpenHtmlUrl("HordeInsideAddress");
					break;
				case 11U:
				{
					PtcC2G_CancelRedDotReq ptcC2G_CancelRedDotReq = new PtcC2G_CancelRedDotReq();
					ptcC2G_CancelRedDotReq.Data.systemid = (uint)XFastEnumIntEqualityComparer<XSysDefine>.ToInt(XSysDefine.XSys_Questionnaire);
					XSingleton<XClientNetwork>.singleton.Send(ptcC2G_CancelRedDotReq);
					XSingleton<XGameSysMgr>.singleton.SetSysRedPointState(XSysDefine.XSys_Questionnaire, false);
					XSingleton<XGameSysMgr>.singleton.RecalculateRedPointState(XSysDefine.XSys_GameCommunity, true);
					GameObject gameObject2 = btn.gameObject.transform.Find("RedPoint").gameObject;
					gameObject2.SetActive(false);
					int questionnaireStage = this.GetQuestionnaireStage();
					dictionary["url"] = XSingleton<XGlobalConfig>.singleton.GetValue(string.Format("QuestionnaireUrl{0}", questionnaireStage));
					dictionary["screendir"] = "SENSOR";
					XSingleton<XUpdater.XUpdater>.singleton.XPlatform.SendExtDara("open_url", Json.Serialize(dictionary));
					break;
				}
				case 12U:
					this.OnReplayClick(btn);
					break;
				case 13U:
						//zcg DlgBase<WebView, WebViewBehaviour>.singleton.SetVisible(true, true);
						break;
				case 14U:
				{
					XSingleton<UiUtility>.singleton.CloseSysAndNoticeServer((uint)XFastEnumIntEqualityComparer<XSysDefine>.ToInt(XSysDefine.XSys_GC_XiaoYueGuanJia));
					btn.gameObject.transform.Find("RedPoint").gameObject.SetActive(false);
					string text2 = (Application.platform == (RuntimePlatform)11) ? "1" : "0";
					string text = string.Format("{0}?game_id={1}&opencode={2}&sig={3}&timestamp={4}&role_id={5}&partition_id={6}&plat_id={7}", new object[]
					{
						XSingleton<XGlobalConfig>.singleton.GetValue("XiaoYueUrl"),
						XSingleton<XGlobalConfig>.singleton.GetValue("XiaoYueGameID"),
						XSingleton<XClientNetwork>.singleton.OpenCode,
						XSingleton<XUpdater.XUpdater>.singleton.XPlatform.GetMD5(string.Format("{0}{1}", XSingleton<XClientNetwork>.singleton.MSDKKey, XSingleton<UiUtility>.singleton.GetTimeStamp())),
						XSingleton<UiUtility>.singleton.GetTimeStamp(),
						XSingleton<UiUtility>.singleton.GetRoleId(),
						XSingleton<XClientNetwork>.singleton.ServerID,
						text2
					});
					XSingleton<XDebug>.singleton.AddLog("url = " + text, null, null, null, null, null, XDebugColor.XDebug_None);
					dictionary["url"] = text;
					dictionary["screendir"] = "SENSOR";
					XSingleton<XUpdater.XUpdater>.singleton.XPlatform.SendExtDara("open_url", Json.Serialize(dictionary));
					break;
				}
				case 15U:
					XSingleton<UiUtility>.singleton.OpenHtmlUrl("LibaozhongxinUrl");
					break;
				}
			}
			return true;
		}

		// Token: 0x0600F89F RID: 63647 RVA: 0x0038E044 File Offset: 0x0038C244
		private bool LoginStateTrue(GameCommunityTable.RowData data)
		{
			bool result;
			if (Application.platform == (RuntimePlatform)7 || Application.platform == (RuntimePlatform)0)
			{
				result = true;
			}
			else
			{
				switch (XSingleton<XLoginDocument>.singleton.Channel)
				{
				case XAuthorizationChannel.XAuthorization_QQ:
					result = data.QQ;
					break;
				case XAuthorizationChannel.XAuthorization_WeChat:
					result = data.WX;
					break;
				case XAuthorizationChannel.XAuthorization_Guest:
					result = data.YK;
					break;
				default:
					result = false;
					break;
				}
			}
			return result;
		}

		// Token: 0x0600F8A0 RID: 63648 RVA: 0x0038E0B0 File Offset: 0x0038C2B0
		public bool IsSuportReplay()
		{
			return Application.platform == (RuntimePlatform)8 && !this.isIpadMode() && XSingleton<XUpdater.XUpdater>.singleton.XPlatform.CheckStatus("is_screen_record_available", "");
		}

		// Token: 0x0600F8A1 RID: 63649 RVA: 0x0038E0F8 File Offset: 0x0038C2F8
		private bool isIpadMode()
		{
			return false;
		}

		// Token: 0x0600F8A2 RID: 63650 RVA: 0x0038E10C File Offset: 0x0038C30C
		private bool OnReplayClick(IXUIButton btn)
		{
			if (DlgBase<ReplaykitDlg, ReplayBehaviour>.singleton.isPlaying || DlgBase<ReplaykitDlg, ReplayBehaviour>.singleton.isReadyPlaying)
			{
				XSingleton<XDebug>.singleton.AddLog("Close Replay..", null, null, null, null, null, XDebugColor.XDebug_None);
				DlgBase<ReplaykitDlg, ReplayBehaviour>.singleton.OnStopClick(null);
			}
			else
			{
				if (DlgBase<BroadMiniDlg, BroadcastMiniBehaviour>.singleton.isBroadcast)
				{
					XSingleton<XDebug>.singleton.AddLog("replay isBroadcasting", null, null, null, null, null, XDebugColor.XDebug_None);
					XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("Replay_IsBroadcasting"), "fece00");
				}
				else
				{
					bool flag2 = XSingleton<XUpdater.XUpdater>.singleton.XPlatform.CheckStatus("is_broadcasting", "");
					XSingleton<XDebug>.singleton.AddLog("open: ", flag2.ToString(), null, null, null, null, XDebugColor.XDebug_None);
					if (!flag2)
					{
						DlgBase<ReplaykitDlg, ReplayBehaviour>.singleton.OpenRepaly();
					}
					else
					{
						if (Application.platform == (RuntimePlatform)7)
						{
							DlgBase<ReplaykitDlg, ReplayBehaviour>.singleton.Show(true);
						}
					}
				}
			}
			return true;
		}

		// Token: 0x0600F8A3 RID: 63651 RVA: 0x0038E218 File Offset: 0x0038C418
		private int GetQuestionnaireStage()
		{
			uint level = XSingleton<XAttributeMgr>.singleton.XPlayerData.Level;
			SeqList<int> sequenceList = XSingleton<XGlobalConfig>.singleton.GetSequenceList("QuestionnaireLevel", true);
			for (int i = 0; i < (int)sequenceList.Count; i++)
			{
				if ((ulong)level >= (ulong)((long)sequenceList[i, 0]) && (ulong)level <= (ulong)((long)sequenceList[i, 1]))
				{
					return i + 1;
				}
			}
			return 0;
		}

		// Token: 0x04006C7A RID: 27770
		private XMainInterfaceDocument _doc = null;

		// Token: 0x04006C7B RID: 27771
		private int _bgWidthDelta;

		// Token: 0x04006C7C RID: 27772
		private bool _widthInit = false;

		// Token: 0x04006C7D RID: 27773
		public IXUISprite m_Bg;

		// Token: 0x04006C7E RID: 27774
		public Transform m_SystemParent;
	}
}
